<?php

class Core_MongoModel extends Core_Model {

    //must have _id
    public $_id;

    /**
     * @return array|false
     */
    public function save() {
        $data = $this->toArray();
        $data = array_filter($data, function ($var) {
            return $var !== NULL;
        });

		$dao = $this->getDao();
		/* @var $dao My_BatchMongoDao */
		$pk = $dao->getPK();
        if ($this->_id instanceof MongoId) {
			$dao->clearMemcache($this->$pk);
            $dao->clearMemcache($this->_id);
            return $this->getTable()->save($data);
        } else {
            //insert
            unset($data['_id']);
            $ret = $this->getTable()->save($data);
            if ($ret) {
                $this->_id = $data['_id'];
                return $this->_id;
            }
            return false;
        }
    }

}